package com.ruoyi.deeplearn.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.deeplearn.domain.DeepClassifyType;
import com.ruoyi.deeplearn.service.IDeepClassifyTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据分类Controller
 *
 * @author rww
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/deeplearn/classifyType")
public class DeepClassifyTypeController extends BaseController
{
    @Autowired
    private IDeepClassifyTypeService deepClassifyTypeService;

    /**
     * 查询数据分类列表
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepClassifyType deepClassifyType)
    {
        startPage();
        List<DeepClassifyType> list = deepClassifyTypeService.selectDeepClassifyTypeList(deepClassifyType);
        return getDataTable(list);
    }

    @GetMapping("/list/all")
    public AjaxResult listAll(DeepClassifyType deepClassifyType)
    {
        List<DeepClassifyType> list = deepClassifyTypeService.selectDeepClassifyTypeList(deepClassifyType);
        return success(list);
    }

    /**
     * 导出数据分类列表
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:export')")
    @Log(title = "数据分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepClassifyType deepClassifyType)
    {
        List<DeepClassifyType> list = deepClassifyTypeService.selectDeepClassifyTypeList(deepClassifyType);
        ExcelUtil<DeepClassifyType> util = new ExcelUtil<DeepClassifyType>(DeepClassifyType.class);
        util.exportExcel(response, list, "数据分类数据");
    }

    /**
     * 获取数据分类详细信息
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepClassifyTypeService.selectDeepClassifyTypeById(id));
    }

    /**
     * 新增数据分类
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:add')")
    @Log(title = "数据分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepClassifyType deepClassifyType)
    {
        return toAjax(deepClassifyTypeService.insertDeepClassifyType(deepClassifyType));
    }

    /**
     * 修改数据分类
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:edit')")
    @Log(title = "数据分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepClassifyType deepClassifyType)
    {
        return toAjax(deepClassifyTypeService.updateDeepClassifyType(deepClassifyType));
    }

    /**
     * 删除数据分类
     */
//    @PreAuthorize("@ss.hasPermi('classifyType:type:remove')")
    @Log(title = "数据分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepClassifyTypeService.deleteDeepClassifyTypeByIds(ids));
    }
}
